<template>
	<view style="padding: 0 30rpx;background-color: #fff;">
		<view class="search-box">
			<view class="input-box">
				<view class="search-icon">
					<text class="uni-icon">&#xe466;</text>
				</view>
				<view class="search-input">
					<input type="text" v-model="formData.msgContent" placeholder="输入想要搜索的内容" />
				</view>
				<view class="close-icon" v-show="formData.msgContent" @click="formData.msgContent=''">
					<text class="uni-icon">&#xe460;</text>
				</view>
			</view>
			<view class="search-btn">
				<text @click="getList(true)">搜索</text>
			</view>
		</view>
		<scroll-view class="list-scroll" scroll-y @scrolltolower="getList()">
			<view class="box-list">
				<view class="box-item">
					<view class="items" v-for="(item,index) in list" :key="index" @click="handleDetail(item)">
						<view class="item">
							<view class="item-label"><text>发布时间</text></view>
							<view class="item-content">{{item.createTime&&item.createTime.slice(0,10)}}</view>
						</view>
						<view class="item">
							<view class="item-label"><text>信息分类</text></view>
							<view class="item-content">{{item.msgType}}</view>
						</view>
						<view class="item">
							<view class="item-label"><text>标题</text></view>
							<view class="item-content">{{item.msgTitle}}</view>
						</view>
						<view class="item">
							<view class="item-label"><text>发布机构</text></view>
							<view class="item-content">{{item.organCode}}</view>
						</view>
					</view>
				</view>
			</view>
			<empty-waybill v-show="list.length==0&&!loading"></empty-waybill>
			<view class="get-more" v-show="andMore">
				加载中<text class="uni-icon">&#xe465;</text>
			</view>
			<view class="get-more" v-show="list.length&&!andMore">
				<text>没有更多了</text>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import emptyWaybill from "@/components/tool-empty/waybill";
	export default {
		components: {
			emptyWaybill
		},
		data() {
			return {
				loading: false,
				list: [],
				pages: {
					size: 10, // 每次加载的数量
					current: 1, // 记录当前页
					total: '', // 记录总数
				},
				formData: {
					msgContent: ""
				},
				tempData: {}
			}
		},
		computed: {
			andMore() {
				// 计算是否还有更多
				return this.pages.total !== this.list.length;
			}
		},
		methods: {
			handleDetail(item) {
				this.$goBack('./detail?param=' + JSON.stringify(item))
			},
			// 加载，刷新
			getList(isRefresh) {
				if (isRefresh) {
					Object.assign(this.tempData, this.formData);
					this.pages.current = 1;
					this.list = [];
				} else {
					if (this.andMore) {
						this.pages.current++;
					} else {
						return;
					}
				}
				this.loading = true;

				const formData = {
					...this.tempData,
					...this.pages
				}
				// console.log(formData);
				this.$api.infoNoticePage(formData).then(res => {
					this.loading = false;
					const resData = res.data.data;
					this.list.push(...resData.records);
					this.pages.total = resData.total;
				})
			},
		},
		mounted() {
			this.getList(true);
		}
	}
</script>

<style lang="scss">
	@keyframes myMove {
		from {
			transform: rotate(0)
		}

		to {
			transform: rotate(360deg);
		}
	}

	.get-more {
		padding: 20rpx;
		text-align: center;
		font-size: 28rpx;

		.uni-icon {
			vertical-align: middle;
			margin-left: 20rpx;
			font-size: 40rpx;
			animation: myMove 2s linear infinite;
		}
	}

	.search-box {
		padding: 30rpx 0;
		display: flex;

		.input-box {
			height: 68rpx;
			flex: 1;
			display: flex;
			padding: 0 30rpx;
			background: #F8F8F8;
			border-radius: 58rpx;

			.search-icon {
				display: flex;
				align-items: center;

				.uni-icon {
					font-size: 28rpx;
					color: #666666;
					vertical-align: middle;
				}
			}

			.search-input {
				flex: 1;
				margin: 0 20rpx;

				input {
					font-size: 28rpx;
					height: 100%;
					width: 100%;
				}
			}

			.close-icon {
				display: flex;
				align-items: center;

				.uni-icon {
					font-size: 28rpx;
					color: #fff;
					vertical-align: middle;
					background-color: #D9D9D9;
					border-radius: 50%;
					padding: 4rpx;
				}
			}
		}

		.search-btn {
			background-color: #007AFF;
			font-size: 28rpx;
			line-height: 58rpx;
			border-radius: 60rpx;
			width: 120rpx;
			margin-left: 16rpx;
			color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}


	.list-scroll ::v-deep {
		height: calc(100vh - 128rpx);
	}

	.box-list {

		.box-item {
			background-color: #fff;
			border-radius: 10rpx;
			margin-bottom: 14rpx;

			&:last-child {
				margin-bottom: 0;
			}

			.label {
				font-size: 28rpx;
				color: #333;
				line-height: 30rpx;
				height: 30rpx;
				padding: 26rpx;
				display: flex;
				align-items: center;
				border-bottom: 1px solid #F0F0F0;


				.img-icon {
					margin-right: 10rpx;
				}
			}

			.items {
				padding: 14rpx 28rpx;
				margin-bottom: 14rpx;
				border-radius: 8rpx;
				border: 1rpx solid rgba(0, 0, 0, 0.1600);

				&:last-child {
					margin-bottom: 0;
				}

				.item {
					font-size: 28rpx;
					line-height: 42rpx;
					padding: 14rpx 0;
					display: flex;

					.item-label {
						color: #666;
						width: 260rpx;
					}

					.item-content {
						color: #333;
						flex: 1;
					}
				}

			}
		}
	}
</style>
